<template>
	<view class="index">
		<Server-index v-if="iFServer&&flag"></Server-index>
		<client-index v-if="!iFServer&&flag"></client-index>
		<setting v-if="settingFlag" :style="{'width': '80%','position': 'fixed','left': 0,'top': 0,'z-index': '999','height': '100%'}"></setting>
		<view v-if="settingFlag" @click="hideSetting" style="width: 100%;height: 100%;position: fixed;z-index: 888;left: 0;top: 0;right: 0;bottom: 0;background-color: rgba(0,0,0,.5);"></view>
	</view>
</template>

<script>
	import clientIndex from "@/components/clientIndex/clientIndex.vue"
	import ServerIndex from "@/components/ServerIndex/ServerIndex.vue"
	import setting from "@/components/setting.vue"
	const app = getApp();
	export default {
		components:{
			clientIndex,
			ServerIndex,
			setting
		},
		created() {
			console.log(666)
		},
		data() {
			return {
				iFServer:true,
				settingFlag:false,
				realHeight:0,
				statusBarH:0,
				navigationHeight:0,
				flag:false
			}
		},
		beforeDestroy() {
			uni.$off('ServerIndex-page');
		}, 
		// onPullDownRefresh() {
		// 	if(this.iFServer){
		// 		uni.$emit("shows")
		// 	}else{
		// 		uni.$emit("showsClient")
		// 	}
		// },
		onLoad(options) {
			console.log(options)
			// #ifdef MP-WEIXIN
			if (options.q) {
				let q = decodeURIComponent(options.q);
				if (q.indexOf("?") != -1) {
					if (app.$vm.getArgs(q, "shareid")) {
						app.$vm.globalData.shareid = app.$vm.getArgs(q, "shareid");
					}
					if (app.$vm.getArgs(q, "cpid")) {
						app.$vm.globalData.cpid = app.$vm.getArgs(q, "cpid");
					}
					if (app.$vm.getArgs(q, "tgid")) {
						app.$vm.globalData.tgid = app.$vm.getArgs(q, "tgid");
					}
					if (app.$vm.getArgs(q, "mdid")) {
						app.$vm.globalData.mdid = app.$vm.getArgs(q, "mdid");
					}
					let type = app.$vm.getArgs(q, "type");
					if(type=='cp'){
						uni.navigateTo({
							url:"/pages/pageone/pages/ActivityDetails/ActivityDetails?id="+app.$vm.globalData.cpid
						})
					}
					if(type=='tg'){
						uni.navigateTo({
							url:"/pages/pagethree/pages/OfferDetails/OfferDetails?id="+app.$vm.globalData.tgid
						})
					}
					if(type=='tpnr'){
						uni.navigateTo({
							url:"/pages/pagetwo/pages/FindDetail/FindDetail?id="+app.$vm.getArgs(q, "nrid")
						})
					}
					if(type=='spnr'){
						uni.navigateTo({
							url:"/pages/pagefive/pages/VideoDetail/VideoDetail?id="+app.$vm.getArgs(q, "nrid")
						})
					}
					if(type=='gr'){
						uni.navigateTo({
							url:"/pages/pageone/pages/Business-card/Business-card?id="+app.$vm.getArgs(q, "usid")
						})
					}
				}
			}
			
			// #endif
			let _this = this;
			// #ifdef MP-WEIXIN
			let res = uni.getMenuButtonBoundingClientRect();
			// #endif
			uni.getSystemInfo({
				success(e) {
					console.log(e);
					_this.navigationHeight = e.statusBarHeight + 50;
					// #ifdef MP-WEIXIN
					// 根据胶囊的位置计算导航栏的高度
					_this.realHeight = (res.top - e.statusBarHeight) *2 + res.height + e.statusBarHeight;
					_this.statusBarH = e.statusBarHeight;
					console.log(_this.realHeight,_this.statusBarH);
					_this.navigationHeight = _this.realHeight;
					// #endif		
					console.log(_this.navigationHeight)
				}
			})
			// wx.setEnableDebug({
			// 	  enableDebug: true
			// 	})
			uni.$on('showSetting',()=>{
				this.settingFlag = !this.settingFlag;
			})
			uni.$on('toggleIdtntity',(res)=>{
				console.log(res);
				
				if(res){
					this.iFServer = false;
				}else{
					this.iFServer = true;
				}
				uni.setStorageSync('identity',res);
				uni.showToast({
					title:"切换成功"
				})
				this.settingFlag = false;
			})
		},
		onShow() {
      // #ifdef APP-PLUS
      var args = plus.runtime.arguments;
      if(args){
        app.$vm.setShareDetail(args);
      }
      // #endif
			if(uni.getStorageSync('identity')){
				this.iFServer = false;
				this.flag = true;
			}else{
				this.iFServer = true;
				this.flag = true;
			}
			if(this.iFServer){
				uni.$emit("shows")
			}else{
				uni.$emit("showsClient")
			}
			console.log(this.iFServer);
		},
		methods: {
			hideSetting(){
				this.settingFlag = false;
			}
		}
	}
</script>

<style scoped>
	
</style>
